package com.ssy.lingxi.purchase.api.enums.needplan;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 需求计划记录 -内部状态
 * 之前的状态使用的中文 并且 message和 NeedPlanInnerStatusEnum 不一致
 * @author lxc
 * @date 2022/02/25
 * @version 2.0.0
 */
public enum NeedPlanInnerRecordStatusEnum {

    TO_BE_EXAM1(1, "待审核(一级)"),
    TO_BE_EXAM2(2, "待审核(二级)"),
    TO_BE_SUBMIT(3, "待提交采购汇总"),
    TO_BE_COLLECT(4, "待汇总需求计划"),
    COLLECT_COMPLETE(5, "已完成"),
    NOT_PASSED1(6, "审核不通过（一级）"),
    NOT_PASSED2(7, "审核不通过（二级）"),
    PURCHASE_RETURN(8, "采购退回");

    private Integer code;
    private String message;

    NeedPlanInnerRecordStatusEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static String getMessage(String message) {
        NeedPlanInnerRecordStatusEnum workEnum = Arrays.stream(NeedPlanInnerRecordStatusEnum.values()).filter(e -> e.getCHMessage().equals(message)).findFirst().orElse(null);
        return null == workEnum ? "" : LanguageHolder.getName(NeedPlanInnerRecordStatusEnum.class, workEnum.getCode());
    }

    public static String getMessage(Integer code) {
        NeedPlanInnerRecordStatusEnum workEnum = Arrays.stream(NeedPlanInnerRecordStatusEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return null == workEnum ? "" : LanguageHolder.getName(NeedPlanInnerRecordStatusEnum.class, workEnum.getCode());
    }

    public static List<Map<String, Object>> getAll() {
        return Arrays.stream(NeedPlanInnerRecordStatusEnum.values()).map(a -> {
            String message = LanguageHolder.getName(NeedPlanInnerRecordStatusEnum.class, a.getCode());
            Map<String, Object> map = new HashMap<>();
            map.put("code", a.getCode());
            map.put("message", message);
            return map;
        }).collect(Collectors.toList());
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    /**
     * 字段类型为Integer
     * @return
     */
    public String getMessage() {
        return LanguageHolder.getName(this.getClass(), this.code);
    }

    /**
     * 字段类型为String
     * @return
     */
    public String getCHMessage() {
        return this.message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
